/**
* Copyright (c) 2016-2100 yunclouds
*/
package com.yunqian.redot.domain;

import com.yunqian.model.BaseModel;
import com.yunqian.redot.constant.BooleanStatus;
import com.yunqian.redot.constant.BusinessType;
import com.yunqian.redot.constant.Tables;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 轮播图管理信息
 *
 * @author zsy
 * 2018-09-29 15:53:43
 */
@Data
@Entity
@Table(name = Tables.BANNER)
@EqualsAndHashCode(callSuper = false)
public class Banner extends BaseModel<Long>{
    
    /**状态*/
    @Column(name = "status")
    private Integer status = BooleanStatus.YES.getCode();
    /**备注*/
    @Column(name = "remark")
    private String remark;
    /**排序号*/
    @Column(name = "sort_num")
    private Integer sortNum;
    /**标题*/
    @Column(name = "title")
    private String title;
    /**轮播图key */
    @Column(name = "img_key")
    private String imgKey;
    /**关联业务枚举(可与内容表枚举保持一致公用之)*/
    @Column(name = "link_type")
    private Integer linkType;
    /**关联业务id*/
    @Column(name = "relate_id")
    private Long relateId;


    @ManyToOne
    @JoinColumn(name = "relate_id", referencedColumnName = "id", insertable = false, updatable = false)
    @Fetch(FetchMode.SELECT)
    @NotFound(action=NotFoundAction.IGNORE)
    public Information information;

    @ManyToOne
    @JoinColumn(name = "relate_id", referencedColumnName = "id", insertable = false, updatable = false)
    @Fetch(FetchMode.SELECT)
    @NotFound(action=NotFoundAction.IGNORE)
    public Courses courses;

    public Banner() {
    }

    public Information getInformation() {
        if(linkType.equals(BusinessType.INFORMATION.getCode())){
            return information;
        }else {
            return null;
        }
    }

    public Courses getCourses() {
        if(linkType.equals(BusinessType.COURSES.getCode())){
            return courses;
        }else {
            return null;
        }
    }
}
